﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

using ZXing;
using ZXing.Common;
using ZXing.QrCode;

namespace DingApi
{
    public partial class prt2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string  move_stock_apply_no = "";
            string sql = "";
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                move_stock_apply_no = Request.QueryString["id"];
            }

            if (move_stock_apply_no.Contains("DB"))
            {
                sql = "     SELECT  "
                        + "    VEHICLE_NO, BILL_STATUS,    TOTAL_WT,TOTAL_NUM,REMARK   "
                        + "    ,to_char(to_date(APPLY_TIME,'yyyymmddhh24miss'),'hh24:mi')   OUT_STOCK_DATE "
                        + "    from  TMM0031 WHERE MOVE_STOCK_TYPE ='BC'   "
                        + "    and   MOVE_STOCK_APPLY_NO  = '" + move_stock_apply_no.Substring(2, move_stock_apply_no.Length-2) + "' "
                        ;

                Label_head.Text = "调拨出库";

            }
            else if (move_stock_apply_no.Contains("XS"))
            { 
                sql = "     SELECT  "
                      + "    VEHICLE_NO, BILL_STATUS,    TOTAL_WT,TOTAL_NUM,REMARK   "
                      + "    ,to_char(to_date(OUT_STOCK_DATE,'yyyymmddhh24miss'),'hh24:mi')   OUT_STOCK_DATE "
                      + "    from  TMM0022 WHERE  OUT_STOCK_MODE='XC' and  Branch_Code = 'N'   "
                      + "    and   OUT_STOCK_NO  = '" + move_stock_apply_no.Substring(2, move_stock_apply_no.Length - 2) + "' "
                      ;
                Label_head.Text = "销售出库";

            }



            EI.EIInfo outBlock = EF.Utility.ExecQuery(sql);
              
            if (outBlock.sys_info.flag == 0  )
            {
                Label1.Text =  move_stock_apply_no; 
                Label2.Text =  outBlock.Tables[0].Rows[0]["VEHICLE_NO"].ToString();
                Label3.Text =  outBlock.Tables[0].Rows[0]["TOTAL_WT"].ToString(); 
                Label4.Text =  outBlock.Tables[0].Rows[0]["OUT_STOCK_DATE"].ToString();

            }



            string content = move_stock_apply_no;
            BarcodeWriter barcodeWriter = new BarcodeWriter();
            barcodeWriter.Format = BarcodeFormat.QR_CODE;

            EncodingOptions options = new EncodingOptions
            {
                Height = 450,
                Width = 450,
                Margin = 0
            }; 
            barcodeWriter.Options = options; 
            Bitmap qrCode = barcodeWriter.Write(content);

            using (MemoryStream ms = new MemoryStream())
            {
                qrCode.Save(ms, ImageFormat.Png);
                byte[] imageBytes = ms.ToArray();
                string base64String = Convert.ToBase64String(imageBytes);
                string qrCodeImage = "data:image/png;base64," + base64String;
                imgQRCode.ImageUrl = qrCodeImage;
            }


        }
    }
}